<link rel="stylesheet" href="/packages/resource/pintuer/pintuer.css">

<div class="pintuer">
    <div class="padding">
        <h5 class="text-yellow">
            微分销申请处理
        </h5>

        <hr class="bg-yellow">


        <div class="line margin-top">
            <form action="/admin" class="form-inline">
                <input type="hidden" name="act" value="proxy_order">
                <input type="hidden" name="op" value="we_distribute_apply">

                <div class="form-group">
                    <div class="field">
                        <div class="input-group">
                            <span class="addon">
                                开始时间：
                            </span>
                            <input type="date" class="input" name="start_time"
                                   value="<?php echo $_GET['start_time'] ?>">
                        </div>
                        <div class="input-group">
                            <span class="addon">
                                开始时间：
                            </span>
                            <input type="date" class="input" name="end_time" value="<?php echo $_GET['end_time'] ?>">
                        </div>

                        <div class="input-group">
                            <span class="addon">会员名</span>
                            <input type="text" name="member_name" class="input" value="<?php echo $_GET['buyer_name'] ?>">
                        </div>
                        <!--                        <div class="input-group">-->
                        <!--                            <span class="addon">收益人ID</span>-->
                        <!--                            <input type="text" name="get_name" class="input" value="--><?php //echo $_GET['get_name'] ?><!--">-->
                        <!--                        </div>-->

                        <div class="button-group">
                            <button type="submit" class="button bg-blue">检索</button>

                        </div>
                    </div>
                </div>

            </form>


            <hr>

            <?php
                if (isset($_GET['parent_id'])) {
                    $member = Model('member')->find($_GET['parent_id']);
                    echo $member['member_name'] . ' 的下级会员';
                }
            ?>

            <table class="table table-bordered">
                <tr class="thead">
                    <th>会员名</th>
                    <th>姓名</th>

                    <th>上级会员</th>
                    <th>申请时间</th>

                    <!--                    <th>联系方式</th>-->
                    <th>身份证号</th>
                    <th>申请留言</th>
                    <th>状态</th>
                    <th>
                        操作
                    </th>
                </tr>
                <?php
                    $m = Model()->table('proxy_apply');
                    $condition = array();
                    if (!empty($_GET['start_time'])) {
                        $condition['time'] = array('gt', strtotime($_GET['start_time']));
                    }

                    if (!empty($_GET['end_time'])) {
                        $condition['time'] = array('lt', strtotime($_GET['end_time']));
                    }

                    if (!empty($_GET['member_name'])) {
                        $member = null;
                        $member = Model('member')->where(['member_name' => $_GET['member_name']])->find();
                        if ($member) {
                            $condition['member_id'] = $member['member_id'];
                        }

                    }

//                    $condition['proxy_member_id'] = 0;


                    $list = $m->where($condition)->page(20)->select();
                    //                    if(!empty($_GET[]))
                    if ($list) {
                        foreach ($list as $item) {

                            ?>
                            <tr>
                                <td>
                                    <?php
                                        $member = Model('member')->find($item['member_id']);
                                        if (empty($member)) {
                                            echo "该会员已被删除";
                                        }
                                        else{
                                            ?>
                                            <a target="_blank" href="javascript:;">
                                            <?php
                                            echo $member['member_name'];
                                            ?>
                                            </a>
                                        <?php
                                        }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $item['name'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        if ($item['proxy_member_id'] == 0) {
                                            echo "无（1级）";
                                        }
                                        else{
                                            $_minfo = ml('member')->find($item['proxy_member_id']);
                                            echo $_minfo['member_name'];
                                        }
                                    ?>
                                </td>

                                <td>
                                    <?php
                                        echo date('Y-m-d H:i:s', $item['time']);
                                    ?>
                                </td>
<!--                                <td>-->
<!--                                    --><?php //echo $item['contact'] ?>
<!--                                </td>-->
                                <td>
                                    <?php echo $item['idcard'] ?>
                                </td>
                                <td>
                                    <?php echo $item['msg'] ?>
                                </td>
                                <td>
                                    <?php
                                    if ($item['status'] == 'state_success') {
                                    ?>
                                        <font style="color: green;">已通过</font>
                                    <?php
                                    }
                                    else if($item['status'] == 'state_cancel') {
                                        echo "<font style='color:red;'>已拒绝</font>";
                                    }else{
                                    ?>
                                        <font style="color: blue;">
                                            未通过
                                        </font>
                                    <?php
                                    }
                                    ?>
                                </td>

                                <td>
                                    <?php
                                        if ($item['status'] == 'state_new' && $item['proxy_member_id'] == 0) {
                                    ?>
                                            <a href="javascript:;" data-id="<?php echo $item['id']?>" class="accept" onclick="return confirm('确定要通过吗？')">
                                                通过
                                            </a>
                                            <span style="padding-left: 10px;padding-right: 10px;">
                                                |
                                            </span>
                                            <a href="javascript:;" data-id="<?php echo $item['id']?>" class="reject" onclick="return confirm('确定要拒绝吗？')">
                                                拒绝
                                            </a>
                                    <?php
                                        }
                                    ?>
                                </td>





                            </tr>
                            <?php
                        }

                    } else {

                    }

                ?>
            </table>

            <link rel="stylesheet" href="/packages/resource/css/pager.css">
            <div class="_pager margin-big-top">
                <?php
                    echo $m->showpage();
                ?>
            </div>
        </div>
    </div>


</div>

<script src="/data/resource/layer/layer.js"></script>
<script>
    $('.accept,.reject').click(function () {
        var id = $(this).attr('data-id');
        var index = layer.load();
        $.get('/admin/?act=proxy_order&op=' + this.className + '&id=' + id,function(msg){
            layer.close(index);
            if(msg == 'success'){
                layer.msg("操作成功",function() {
                    location.reload();
                });
            }
            else{
                layer.msg("操作失败");
            }

        });
//        layer.msg("调试中，请不要操作");
    });
</script>

